package com.example.dllo.moondog.contact;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.dllo.moondog.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/3/4.
 */
public class UserListViewAdapter extends BaseAdapter {
    private List<String> data;
    private Context context;

    public UserListViewAdapter(List<String> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder myViewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_listview_fragment_contact,parent,false);
            myViewHolder = new MyViewHolder(convertView);
            convertView.setTag(myViewHolder);
        } else {
            myViewHolder = (MyViewHolder) convertView.getTag();
        }

        myViewHolder.usernameTextView.setText(data.get(position));

        return convertView;
    }

    class MyViewHolder {
        private TextView usernameTextView;
        public MyViewHolder(View view) {

            usernameTextView = (TextView) view.findViewById(R.id.tv_username);

        }
    }
}
